﻿using System;
using Microsoft.Extensions.DependencyInjection;

namespace FrameworkCore.Dependency
{
    public sealed class ServiceLocator
    {

        public static ServiceLocator Instance= new ServiceLocator(); 
        private static IServiceProvider _provider;
        private ServiceLocator()
        {

        }


        /// <summary>
        /// 设置应用程序服务提供者
        /// </summary>
        public void SetApplicationServiceProvider(IServiceProvider provider)
        {
         
            _provider = provider;

        }





        /// <summary>
        /// 得到服务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>

        public T GetService<T>() => _provider.GetService<T>();

    }
}
